{
 "metadata": {
  "name": "plot_colors"
 },
 "nbformat": 2,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "source": [
      "#Coloring"
     ]
    },
    {
     "cell_type": "markdown",
     "source": [
      "",
      "",
      "### Cartesian Line Plot"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "from sympy.plotting import plot, plot_parametric, plot3d, plot3d_parametric_line, plot3d_parametric_surface"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p = plot(sin(x))"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "source": [
      "",
      "",
      "If the `line_color` aesthetic is a function of arity 1 then the coloring is a function of the x value of a point."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].line_color = lambda a : a",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "source": [
      "",
      "",
      "If the arity is 2 then the coloring is a function of both coordinates."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].line_color = lambda a, b : b",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "markdown",
     "source": [
      "### Parametric Lines"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p = plot_parametric(x*sin(x), x*cos(x), (x,  0, 10))"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 5
    },
    {
     "cell_type": "markdown",
     "source": [
      "",
      "",
      "If the arity is 1 the coloring depends on the parameter."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].line_color = lambda a : a",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 6
    },
    {
     "cell_type": "markdown",
     "source": [
      "",
      "",
      "For arity 2 the coloring depends on coordinates."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].line_color = lambda a, b : a",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 7
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].line_color = lambda a, b : b",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 8
    },
    {
     "cell_type": "markdown",
     "source": [
      "### 3D Parametric line"
     ]
    },
    {
     "cell_type": "markdown",
     "source": [
      "",
      "",
      "Arity 1 - the first parameter. Arity 2 or 3 - the first two coordinates or all coordinates."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p = plot3d_parametric_line(sin(x)+0.1*sin(x)*cos(7*x),",
      "",
      "         cos(x)+0.1*cos(x)*cos(7*x),",
      "",
      "         0.1*sin(7*x),",
      "",
      "         (x, 0, 2*pi))"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 9
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].line_color = lambda a : sin(4*a)",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 10
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].line_color = lambda a, b : b",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].line_color = lambda a, b, c : c",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 12
    },
    {
     "cell_type": "markdown",
     "source": [
      "### Cartesian Surface Plot"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p = plot3d(sin(x)*y, (x, 0, 6*pi), (y, -5, 5))"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 14
    },
    {
     "cell_type": "markdown",
     "source": [
      "",
      "",
      "Arity 1, 2 or 3 for first, the two first or all coordinates."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].surface_color = lambda a : a",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 15
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].surface_color = lambda a, b : b",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 16
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].surface_color = lambda a, b, c : c",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 17
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].surface_color = lambda a, b, c : sqrt((a-3*pi)**2+b**2)",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 18
    },
    {
     "cell_type": "markdown",
     "source": [
      "### Parametric surface plots"
     ]
    },
    {
     "cell_type": "markdown",
     "source": [
      "",
      "",
      "Arity 1 or 2 - first or both parameters."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p = plot3d_parametric_surface(x*cos(4*y), x*sin(4*y), y,",
      "",
      "         (x, -1, 1), (y, -1, 1))"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 19
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].surface_color = lambda a : a",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 20
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].surface_color = lambda a, b : a*b",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 21
    },
    {
     "cell_type": "markdown",
     "source": [
      "Arrity of 3 will color by coordinates."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p[0].surface_color = lambda a, b, c : sqrt(a**2+b**2+c**2)",
      "",
      "p.show()"
     ],
     "language": "python",
     "outputs": [],
     "prompt_number": 22
    }
   ]
  }
 ]
}